package com.tedu.ds.coupon.controller;

import com.tedu.ds.base.response.JsonResult;
import com.tedu.ds.coupon.pojo.dto.CouponQuery;
import com.tedu.ds.coupon.pojo.dto.CouponSaveParam;
import com.tedu.ds.coupon.pojo.entity.Coupon;
import com.tedu.ds.coupon.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping(value = "/v1/coupon")
@RestController
@Api(tags = "优惠券管理")
public class CouponController {
    @Autowired
    private CouponService couponService;
    @PostMapping("/save")
    @ApiOperation(value = "优惠券新增/修改")
    public JsonResult save(@RequestBody CouponSaveParam param) {
        couponService.save(param);
        return JsonResult.ok();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "优惠券删除")
    @ApiImplicitParam(name = "id", value = "优惠券ID", required = true)
    public JsonResult delete(@PathVariable Integer id) {
        couponService.deleteById(id);
        return JsonResult.ok();
    }
    @PostMapping("/select")
    @ApiOperation(value = "优惠券查询")
    public JsonResult select(@RequestBody CouponQuery query) {
        List<Coupon> list = couponService.select(query);
        return JsonResult.ok(list);
    }
    @PostMapping("/update")
    @ApiOperation(value = "优惠券修改")
    public JsonResult update(@RequestBody CouponSaveParam param) {
        couponService.update(param);
        return JsonResult.ok();
    }
}
